﻿using System;
using System.Windows.Forms;
using ReportWizard.DataAccess;
using ReportWizard.Helpers;
using ReportWizard.Interface;
using ReportWizard.Properties;

namespace ReportWizard.Forms
{
    public partial class CreateBaseObjectForm : IconForm
    {
        private IBookmark CurrentBookmark { get; set; }

        public CreateBaseObjectForm(IBookmark currentBookmark)
        {
            InitializeComponent();

            CurrentBookmark = currentBookmark;

            ShowCustomRightButton = false;
            ShowCustomLeftButton = false;
            ShowCheckFooter = false;
        }

        private void CreateEntityFormLoad(object sender, EventArgs e)
        {
            Text = string.Format("Новое значение для поля \"{0}\"", Globals.TargetFormProfile);
        }

        private void CreateClick(object sender, EventArgs e)
        {
            string entityName = tbName.Text.Trim();
            if (entityName.Length != 0 && CurrentBookmark != null)
            {
                ReportBaseObject objToSave = new ReportBaseObject(CurrentBookmark.Id, tbName.Text.Trim(), CurrentBookmark is BookmarkGroup);
                objToSave.Insert(true, CurrentBookmark is BookmarkGroup);
                DialogResult = DialogResult.OK;
            }
            else
            {
                ShowMessage.Info(Resources.SetNameForNewObject);
            }
        }

        private void CancelClick(object sender, EventArgs e)
        {
            Close();
        }
    }
}
